package com.altersoftware.hotel.dao;

import java.util.List;

import org.apache.ibatis.annotations.*;

import com.altersoftware.hotel.entity.PermissionCustomerDO;

/**
 * @author czy@win10
 * @date 2020/1/22 18:18
 */
@Mapper
public interface PermissionCustomerDAO {

    /**
     * 插入一条客户权限
     *
     * @param permissionCustomerDO
     */
    @Insert(" INSERT INTO tb_permissioncustomer ( id, permission_number, customer_number, create_time, modify_time ) "
        +
        "VALUES(#{id}, #{permissionId}, #{customerId}, NOW(), NOW()) ")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insert(PermissionCustomerDO permissionCustomerDO);

    /**
     * 删除客户权限
     *
     *
     */
    @Delete("DELETE FROM tb_permissioncustomer WHERE id=#{id}")
    void deleteById(long id);

    /**
     * id查询客户权限
     *
     * @param id
     * @return
     */
    @Select(" select permission_number, customer_number, id, create_time, modify_time"
        +
        " from tb_permissioncustomer where permission_number=#{id} ")
    @Results({
        @Result(property = "id", column = "id"),
        @Result(property = "permissionId", column = "permission_number"),
        @Result(property = "customerId", column = "customer_number"),
        @Result(property = "createTime", column = "create_time"),
        @Result(property = "modifyTime", column = "modify_time")
    })
    PermissionCustomerDO getPermissionCustomerById(long id);

    /**
     * 客户id查询权限集合
     *
     * @param customerId
     */
    @Select(" select permission_number, customer_number, id, create_time, modify_time"
        +
        " from tb_permissioncustomer where customer_number=#{customerId} ")
    @Results({
        @Result(property = "id", column = "id"),
        @Result(property = "permissionId", column = "permission_number"),
        @Result(property = "customerId", column = "customer_number"),
        @Result(property = "createTime", column = "create_time"),
        @Result(property = "modifyTime", column = "modify_time")
    })
    List<PermissionCustomerDO> getPermissionCustomerListBycustomerId(long customerId);
}
